using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// iconsize 1 = small
/// iconsize 2 = medium
/// iconsize 3 = large
/// </summary>
public class PageIcons
{
    HDDatabase Hdd;
    private string path = "Images/MBIcons/";
    public static string strdefaulticon = "Images/MBIcons/Small/Default.PNG";
	public PageIcons()
	{
		//
		// TODO: Add constructor logic here
		//
        
	}

    public Hashtable geticons(string pageid)
    {
        Hdd = new HDDatabase();
        Hashtable ht = new Hashtable(3);
        try
        {

            string iconname = Hdd.GetColumnValue("sy_pg", "page_icon", "page_id = '" + pageid + "'");
            if (iconname != "")
            {
                ht.Add(1, path + "Small/" + iconname);
                ht.Add(2, path + "Medium/" + iconname);
                ht.Add(3, path + "Large/" + iconname);
            }
            else
            {
                ht.Add(1, path + "Small/Default.PNG");
                ht.Add(2, path + "Medium/Default.PNG");
                ht.Add(3, path + "Large/Default.PNG");
            }

            
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("ERROR :geticons(string)"+ ex.Message);

            ht.Add(1, path + "Small/Default.PNG");
            ht.Add(2, path + "Medium/Default.PNG");
            ht.Add(3, path + "Large/Default.PNG");

            
        }
        finally
        {
            Hdd = null;
        }
        return ht;


    }
    public string geticons(string pageid, int iconsize)
    {
        Hdd = new HDDatabase();
        string result = "";

        try
        {
            string iconname = CommonFunctions.GetColValueFromPageInfo((HttpContext.Current.Request.QueryString["pgs_id"] == null ? "" : HttpContext.Current.Request.QueryString["pgs_id"].ToString()), "sy_pg", "page_icon", "page_id = '" + pageid + "'");
            if (iconname == "") iconname = Hdd.GetColumnValue("sy_pg", "page_icon", "page_id = '" + pageid + "'");
            if (iconname != "")
            {
                switch (iconsize)
                {
                    case 1:
                        result = path + "Small/" + iconname;
                        break;
                    case 2:
                        result = path + "Medium/" + iconname;
                        break;
                    case 3:
                        result = path + "Large/" + iconname;
                        break;
                    default:
                        result = path + "Small/" + iconname;
                        break;

                }
            }
            else
            {
                switch (iconsize) // Added by 'Imran Gani' on 23/05/12, to get the required size of Default page icon.
                {
                    case 1:
                        result = path + "Small/default.PNG";
                        break;
                    case 2:
                        result = path + "Medium/default.PNG";
                        break;
                    case 3:
                        result = path + "Large/default.PNG";
                        break;
                    default:
                        result = path + "Small/default.PNG";
                        break;
                }
                //result = path + "Small/default.PNG"; // Commanded by 'Imran Gani' on 23/05/12, to get the required size of page icon.
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("ERROR :Geticons(string,int)" + ex.Message);
            result= path+"Small/default.PNG";
            
        }
        finally
        {
            Hdd = null;
        }

        return result;
    }


    public string geticonsfrompageset(string strPagesetRowId, int iconsize)
    {
        Hdd = new HDDatabase();
        string result = "";

        try
        {
            //string pagesetafrowid = CommonFunctions.GetColValueFromPageInfo(strPagesetRowId, "sy_pgs", "af_row_id", "pageset_id = '" + strPagesetRowId + "'");
            //if (pagesetafrowid == "") pagesetafrowid = Hdd.GetColumnValue("sy_pgs", "af_row_id", "pageset_id = '" + strPagesetRowId + "'");
            string page_id = CommonFunctions.GetColValueFromPageInfo(strPagesetRowId, "sy_pgs_mem", "page_id", "pageset_id='" + strPagesetRowId + "'");
            if (page_id == "") page_id = Hdd.GetColumnValue("sy_pgs_mem", "page_id", "pageset_id='" + strPagesetRowId + "'");

            result = geticons(page_id, iconsize);
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error geticonsfrompageset:"+ex.Message);
            result = path + "Small/default.PNG";
        }
        finally
        {
            Hdd = null;
        }
        return result;
    }

    public string geticontextfrompageset(string strPagesetRowId, int iconsize)
    {
        Hdd = new HDDatabase();
        string result = "";

        try
        {
            //string pagesetafrowid = Hdd.GetColumnValue("sy_pgs", "af_row_id", "pageset_id = '" + strPagesetRowId + "'");
            string page_id = Hdd.GetColumnValue("sy_pgs_mem", "page_id", "pageset_id='" + strPagesetRowId + "'");

            result = geticons(page_id, iconsize);
            result = "<img src=" + result + "></img>";
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error geticonsfrompageset:" + ex.Message);
            result = "<img src=" + path + "Small/default.PNG></img>";
        }
        finally
        {
            Hdd = null;
        }
        return result;
    }


}
